<?php

namespace App\Services;

class AgentRewardRuleSettings
{
    public static function getSettingsByCache($type = null)
    {
        $settings = \Cache::remember('reward_settings', 86400, function () {
            return \App\Models\AgentRewardRuleSettings::query()->get()->toArray();
        });

        if ($type !== null) {
            return array_filter($settings, fn ($setting) => $type === $setting['type'] );
        }

        return $settings;
    }

    public static function forgetSettingsCache()
    {
        return \Cache::forget('reward_settings');
    }
}
